package api.db;

import api.TestCase;
import lombok.SneakyThrows;
import org.apache.commons.dbutils.BasicRowProcessor;
import org.apache.commons.dbutils.GenerousBeanProcessor;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ColumnListHandler;
import org.apache.commons.dbutils.handlers.MapListHandler;

import java.util.List;
import java.util.Map;


public class ApiTestDb {

    //读取所有参数 List<Map<>>
    @SneakyThrows
    public static List<Map<String,Object>> getAllParams(){
        return JDBCUtils.getQueryRunner2().query("SELECT * FROM tb_busnies", new MapListHandler());
    }


    //开启 业务
    @SneakyThrows
    public static List<TestCase> getTestCase(String business){
        String sql ="select * from tb_api_case where business=? and run=1 order by order_num";
        return JDBCUtils.getQueryRunner2().query(sql, new BeanListHandler<TestCase>(TestCase.class,new BasicRowProcessor(new
                GenerousBeanProcessor())), business);
    }

    //读取allbusiness

   // SELECT DISTINCT(business) from tb_busnies;
   @SneakyThrows
    public static List<String> getAllbusiness(){
        String sql ="SELECT DISTINCT(business) from tb_busnies;";
        return JDBCUtils.getQueryRunner2().query(sql, new ColumnListHandler<String>(1));
    }


    public static void main(String[] args) {
       // System.out.println(getAllParams());
      //  getTestCase("登录业务").forEach(d-> System.out.println(d));
        getAllbusiness().forEach(d-> System.out.println(d));
    }
}
